<template>
<div>
  <el-dialog
    width="30%"
    :title="'申请报修'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="110px" size="mini" label-position="left">
      <el-form-item label="工夹具代码" prop="code">
        <el-input v-model="dataForm.code" placeholder="工夹具代码"></el-input>
      </el-form-item>
      <el-form-item label="工夹具序列号" prop="seqId">
        <el-input v-model="dataForm.seqId" placeholder="工夹具序列号"></el-input>
      </el-form-item>
      <hr style="opacity: 0.3"><br>
      <el-form-item label="报修原因" prop="repairReason">
        <el-input
          type="textarea"
          :rows="2"
          placeholder="报修原因"
          v-model="dataForm.repairReason">
        </el-input>
      </el-form-item>
      <el-form-item label="故障图片" prop="scrapPhotoUrl">
        <single-upload @input="getScrapPhotoUrl"></single-upload>
        <img width="50%" :src="dataForm.repairPhotoUrl">
      </el-form-item>
    </el-form>
    <hr style="opacity: 0.3"><br>
    <span slot="footer" class="dialog-footer">
      <el-button @click="close">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
import SingleUpload from "../../../components/upload/singleUpload";

export default {
  name: "repairsubmitmineadd",
  data () {
    return {
      visible: false,
      dataForm: {
        id: 0
      },
      dataRule: {
        seqId: [
          { required: true, message: '工夹具序列号不能为空', trigger: 'blur' }
        ],
        code: [
          { required: true, message: '工夹具代码不能为空', trigger: 'blur' }
        ],
        repairReason: [
          { required: true, message: '报修原因不能为空', trigger: 'blur' }
        ],
        repairPhotoUrl: [
          { required: true, message: '故障图片不能为空', trigger: 'blur' }
        ],
      }
    }
  },
  components:{
    SingleUpload
  },
  methods: {
    close(){
      this.visible = false
      this.dataForm = {}
    },
    getScrapPhotoUrl(url){
      this.dataForm.repairPhotoUrl = url
    },
    init (id) {
      console.log(1111111111111111)
      this.dataForm.id = id || 0
      this.visible = true
      this.$nextTick(() => {
        console.log(2222222222222222222)
        console.log(this.dataForm.id)
        this.$refs['dataForm'].resetFields()
        if (this.dataForm.id !== 0) {
          console.log(333333333333333333333)
          this.$http({
            url: `http://localhost:10000/gongjiajumain/scrapsubmit/info/${this.dataForm.id}`,
            method: 'get',
            params: this.$http.adornParams()
          }).then(data => {
            console.log(data)
            this.dataForm = data.data.scrapSubmit
          })
        }else {

        }
      })
    },
    // 表单提交
    dataFormSubmit () {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$http({
            url: ``,
            method: 'post',
            data: this.$http.adornData({
              'id': this.dataForm.id || undefined,
              'seqId': this.dataForm.seqId,
              'code': this.dataForm.code,
              'submitId': this.dataForm.submitId,
              'usedCount': this.dataForm.usedCount,
              'scrapReason': this.dataForm.scrapReason,
              'scrapPhotoUrl': this.dataForm.scrapPhotoUrl,
              'firstAcceptor': this.dataForm.firstAcceptor,
              'firstTime': this.dataForm.firstTime,
              'firstReason': this.dataForm.firstReason,
              'finalAcceptor': this.dataForm.finalAcceptor,
              'finalTime': this.dataForm.finalTime,
              'finalReason': this.dataForm.finalReason,
              'status': this.dataForm.status
            })
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.visible = false
                  this.$emit('refreshDataList')
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
